<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let tree = {
                val: 1,
                left: {
                    val: 2,
                    left: {
                        val: 4,
                        left: {
                            val: 8,
                        },
                        right: {
                            val: 12,
                        },
                    },
                    right: {
                        val: 5,
                        left: {
                            val: 10,
                        },
                        right: {
                            val: 13,
                        },
                    },
                },
                right: {
                    val: 3,
                    left: {
                        val: 6,
                        left: {
                            val: 16,
                        },
                        right: {
                            val: 11,
                        },
                    },
                    right: {
                        val: 7,
                        left: {
                            val: 9,
                        },
                    },
                },
            }
            var minCameraCover = function (root) {
                //所有后序遍历的是左右根的顺序
                if (!root) return null
                let left = minCameraCover(root.left) //如果有返回值，得到的其实是左右子节点。因为后序遍历先得到左右子节点，然后是根
                let right = minCameraCover(root.right)
                console.log('当前节点', root.val, '左节点', left, '右节点', right)
                return root.val //返回当前节点的值，就是把当前节点作为子节点返回
            }
            minCameraCover(tree)
        </script>
    </body>
</html>
